//
//  SIAccountSocialAccountMoreCell.swift
//  Signum
//
//  Created by x-men on 2023/1/13.
//

import UIKit

class SIAccountSocialAccountDisconnectCell: UICollectionViewCell {
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.text = ""
        label.textColor = .black
        label.textAlignment = .center
        label.numberOfLines = 0
        //label.adjustsFontSizeToFitWidth = true
        return label
    }()
    
    lazy var iconImageV: UIImageView = {
        let imageV = UIImageView()
        imageV.contentMode = .scaleAspectFill
        return imageV
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        configUi()
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configUi() {
        self.contentView.addSubview(iconImageV)
        iconImageV.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        self.contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
}


class SIAccountSocialAccountMoreCell: UITableViewCell {
    
    let itemW = 60.0
    
    var collectionView : UICollectionView!
    
    var moreBlock : (()->())?
    
    var dataArray:[String] = ["account-instagram-disconnect","account-twitter-disconnect","account-linkedin-disconnect","account-facebook-disconnect"]
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        configUi()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func configUi() {
        self.backgroundColor = .clear
        configCollectionView()
    }
    
    func configCollectionView() {
        
        let layout = UICollectionViewFlowLayout()
        // 设置滚动的方向
        layout.scrollDirection = .horizontal;
        // 行间距
        layout.minimumLineSpacing = 24
        // 设置cell之间的间距
        layout.minimumInteritemSpacing = 24;
        collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
        collectionView.setCollectionViewLayout(layout, animated: false)
        collectionView.backgroundColor = UIColor.clear
        collectionView.showsHorizontalScrollIndicator = false;
        collectionView.showsVerticalScrollIndicator = false;
        collectionView.isPagingEnabled = false;
        collectionView.alwaysBounceHorizontal = true;
        collectionView.dataSource = self;
        collectionView.delegate = self;
        collectionView.register(SIAccountSocialAccountDisconnectCell.self, forCellWithReuseIdentifier: NSStringFromClass(SIAccountSocialAccountDisconnectCell.self))
        self.contentView.addSubview(collectionView)
        collectionView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(21)
            make.right.equalToSuperview().offset(-21)
            make.height.equalTo(itemW)
            make.top.equalToSuperview().offset(15)
            make.bottom.equalToSuperview().offset(-15)
        }
        
    }
    
}

extension SIAccountSocialAccountMoreCell: UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataArray.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(SIAccountSocialAccountDisconnectCell.self), for: indexPath) as? SIAccountSocialAccountDisconnectCell {
            let imageName = dataArray[indexPath.item]
            cell.iconImageV.image = UIImage(named: imageName)
            return cell
        }
        return UICollectionViewCell()
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
    }
    
    //返回item高度的方法
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        //找出最大的数组数
        return CGSize(width: itemW, height:itemW)
    }
    
}
